package com.xxx.service;

import com.xxx.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/8/18 14:22
 * @Copyright 博为峰
 */
@Service("accountService")
//@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 3000, readOnly = false, rollbackFor = RuntimeException.class)
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

//    @Autowired
//    private DataSourceTransactionManager transactionManager;

//    @Autowired
//    private TransactionTemplate transactionTemplate;

    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 3000, readOnly = false, rollbackFor = RuntimeException.class)
    @Override
    public void transfer(String from, String to, int money) {
        //zhangsan转账给lis   zhangsan的-money  lisi的+money
        accountDao.updateAccount(from, -money);
        System.out.println(1 / 0);
        accountDao.updateAccount(to, money);
    }
}
